//
// Created by 39442 on 2025/10/4.
//

#include "MyThread.h"

#include <utility>

int MyThread::generateId_ = 0;

//构造和析构
MyThread::MyThread(ThreadFunc func) :
    func_(std::move(func)), threadId_(generateId_++)
{
}

MyThread::~MyThread() = default;

//启动线程
void MyThread::start()
{
    //创建一个线程，执行一个线程函数
    std::thread t(func_, threadId_);
    t.detach();	//设置分离线程
}

int MyThread::getId() const
{
    return threadId_;
}